Skip to content

Fix: Variable overrides for dbt packages#5376

Merged
izeigerman merged 1 commit into
mainfrom
fix-var-overrides-for-dbt-packages
Sep 15, 2025
Merged

Fix: Variable overrides for dbt packages#5376
izeigerman merged 1 commit into
mainfrom
fix-var-overrides-for-dbt-packages

Conversation

@izeigerman

Copy link
Copy Markdown
Collaborator

I've realized that I missed another edge case.

@izeigerman izeigerman requested review from a team and Copilot September 15, 2025 17:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an edge case in variable override handling for dbt packages by ensuring that SQLMesh config variable overrides are properly applied to all packages.

  • Adds variable override application to ensure SQLMesh config variables take precedence over dbt project variables
  • Introduces test coverage to verify variable overrides work correctly across all packages

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/fixtures/dbt/sushi_test/config.py Adds test configuration with variable overrides
tests/dbt/test_config.py Adds test to verify variable overrides are applied to all packages
sqlmesh/dbt/project.py Ensures variable overrides are applied to all packages after other variable resolution

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread sqlmesh/dbt/project.py
Comment on lines +116 to 118
if variable_overrides:
package.variables.update(variable_overrides)

Copilot AI Sep 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable override logic is duplicated - it's already applied in all_project_variables on line 102. This second application is redundant since all_project_variables already includes the overrides and is applied to packages on lines 109 and 115.

Suggested change
if variable_overrides:
package.variables.update(variable_overrides)

Copilot uses AI. Check for mistakes.

@izeigerman izeigerman Sep 15, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong! Below is the scenario the previous logic didn't handle:

For a variable with name package_var and the following setup:

  1. --var 'package_var: overridden_from_cli'
  2. In the project's dbt_project.yml:
vars:
  target_package:
    package_var: overridden_from_root_project
  1. In the package's dbt_project.yml:
vars
  package_var: default_value

The old logic returned overridden_from_root_project instead of overridden_from_cli.

@izeigerman izeigerman merged commit 1b2979b into main Sep 15, 2025
36 checks passed
@izeigerman izeigerman deleted the fix-var-overrides-for-dbt-packages branch September 15, 2025 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants